<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>知识管理</title>
    <style>
        .nicescroll-rails.nicescroll-rails-vr{
            background: transparent!important;
            left:2.715rem!important;
        }
    </style>
</head>
<body style="width:100%">
		<div class="right-top-tools" style="height:50px">
            <div class="zd-tab clearfix" style="height:50px">
               <span style="color:#3c619e;font-weight: bold">知识管理  </span>
            </div>
        </div>
		<div class="table_filter"  style="height:50px;text-align:left; padding-top:6px; margin-top:30px">
			<div class="dataTables_filter" id="searchDiv">
				<input style="width: 200px;" placeholder="请输入查询条件" id="likeFilter" name="likeFilter" class="form-control" type="search" likeoption="true">
				<div class="btn-group" style="margin-left:6px">
					<button type="button" class="btn btn-primary" data-btn-type="search" onclick="search()">查询</button>
					<button type="button" class="btn btn-default" data-btn-type="reset" onclick="likeFilterReset()">重置</button>
				</div>
				<div class="btn-group" style="float:right;display:none" id="btns">
					<button id="knowledge_new" type="button" class="btn btn-default" data-btn-type="add">新增</button>
					<button id="knowledge_edit" type="button" class="btn btn-default" data-btn-type="edit">编辑</button>
					<button id="knowledge_show" type="button" class="btn btn-default" data-btn-type="add">查看</button>
					<button id="knowledge_delete" type="button" class="btn btn-default" data-btn-type="delete">删除</button>
				</div>
			</div>
		</div>
        <div class="table-container" style="margin-top:0px" >
            <table id="knowledge_table" class="display" cellspacing="0" width="100%">
                <thead>
                <tr>
                    <th style="text-align:center">标题</th>
                    <th style="text-align:center">类别</th>
                    <th style="text-align:center">作者</th>
                    <th style="text-align:center">创建时间</th>
                </tr>
                </thead>
            </table>
        </div>

<!-- <script type="text/javascript" src="../../js/geological/public.js"></script> -->
<script type="text/javascript">
	var Dtable_knowledge = null;
	
	function search(){
		Dtable_knowledge.ajax.reload()
	}
	
	function likeFilterReset(){
		$("#likeFilter").val("")
		Dtable_knowledge.ajax.reload()
	}
	
	function showKnowledgeTable( _city_code ){
		var _pagesize = 5;
    	var _url = "../../tbl_knowledge_base/list";
    	city_code = _city_code;
    	
    	Dtable_knowledge = $('#knowledge_table').DataTable( {
	        "info":0,
	        "pageLength": _pagesize,
	        "lengthChange":false,
	        "searching":false,
	        "ordering":true,
	        "processing": true,
	        "serverSide": true,
	        "ajax": { 
	        	url: _url,  
	        	type: "post",
	        	contentType: "application/json",
	            dataType: "json",
	            data: function( data ) {
	            	if( data.order && data.order.length > 0 && data.columns && data.columns.length > 0 ){
	            		data.orderIndex = data.order[0].column;
	            		if( data.columns.length >= ( data.orderIndex + 1 )){
	            			data.orderColName = data.columns[data.orderIndex].data;
	            		}
	            		data.orderType = data.order[0].dir;
	            	}
	            	//模糊查询
	            	if( $("#likeFilter").val() != null && $("#likeFilter").val() != "" ){
	            		data.likeFilter = $("#likeFilter").val();
	            	}
	            	
	                data.page = data.start/data.length + 1;
	                data.pagesize = _pagesize;
	                return JSON.stringify(data);
	            },
	            dataSrc: function ( json ) {
	            	$(json.data).each(function(){
	            		this.create_time = new Date(this.create_time).format("yyyy年MM月dd日");
	            	});
	            	json.recordsTotal = json.pagination.totalRecord;
	            	json.recordsFiltered = json.pagination.totalRecord;
	            	return json.data;
	            }
	        },
	        "columns": [
	            { "data": "title" },
	            { "data": "type" },
	            { "data": "author" },
	            { "data": "create_time" }
	        ],
	        "language": {
	            "paginate": {
	                "next": "下一页",
	                "previous": "上一页",
	            }
	        }
	    } );
    	
    	$('#knowledge_table tbody').on( 'click', 'tr', function () {
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }else {
                $('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
        } );
	}
	
    $(document).ready(function(){
    	
    	if("ADMIN" == global.currentRole) {
    		$("#btns").show();
    	}
    	
	    $("#knowledge_new").click( function(){
	    	//global.showModal("创建新知识点", "knowledge/knowledge_create.html");
	    	global.showModal("创建知识点", "knowledge/knowledge_ueditor.jsp");
	    });
	    
	    $("#knowledge_show").click( function(){
	    	if( Dtable_knowledge.rows('.selected').data().length == 0 ){
	    		global.alert('请选择一条您需要查看的信息！');
	    	}else{
	    		global.showModal("查阅知识点", "knowledge/knowledge_show.jsp");
	    	}	
	    });
	    
	    $("#knowledge_edit").click(function(){
	    	if( Dtable_knowledge.rows('.selected').data().length == 0 ){
	    		global.alert('请选择一条您需要编辑的信息！');
	    	}else{
	    		global.showModal("编辑知识信息", "knowledge/knowledge_ueditor.jsp");
	    	}	    	
	    });
	    
	    $("#knowledge_delete").click(function(){
	    	if( Dtable_knowledge.rows('.selected').data().length == 0 ){
	    		global.alert('请选择一条您需要编辑的信息！');
	    	}else{
	    		$.confirm({
	        	    title: "删除操作确认！",
	        	    content: "您确认需要删除这一条信息吗，请谨慎操作，数据可能无法恢复！",
	        	    buttons: {
	        	    	confirm:{
	        	    		btnClass: 'btn-blue',
	        	    		text: '直接删除', // Some Non-Alphanumeric characters
		                    action: function(){
		                    	var id = Dtable_knowledge.rows('.selected').data()[0].id;
		    		    		var url = "../../tbl_knowledge_base/" + id;
		    		    		$.ajax({
		    		    			  url: url,
		    		    			  type : 'delete',
		    		    			  async : false,
		    		    			  contentType: "application/json; charset=utf-8",
		    		    			  dataType: "json",
		    		    			  success: function(json) {
		    		    				 global.alert( json.message );
		    		    				 $("#knowledge_main").load("knowledge/knowledge_list.html");
		    		    			  }
		    		    		});
		                    }
	        	    	},
	        	    	cancel: {
	        	    		text: '暂不删除',
	        	        },
	        	    }
	        	});
	    	}
	    });	
	    
	    showKnowledgeTable();
    });    

</script>
</body>
</html>